package com.yuyin.web;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: LCG
 * @date: 2022-11-04 14:10:35
 * @description:
 **/
@RestController
public class TestBoBaoController {

    @RequestMapping("yuyin")
    private void test02(){
        TestBoBaoController.speakingText("李小明，运动时间已结束，请离开场地,点一份盖浇饭，不要辣椒，多放一些鸡蛋，欧拉");
    }

    public static void main(String[] args) {
        speakingText("李小明，运动时间已结束，请离开场地！");
    }

    /**【语音播报方法】**/
    public static boolean speakingText(String readText){
        boolean isFinish = true;
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
        try {
            // 音量 0-100
            sap.setProperty("Volume",new Variant(100));
            // 语音朗读速度 -10 到 +10
            sap.setProperty("Rate",new Variant(1));
            // 获取执行对象
            Dispatch sapo = sap.getObject();
            // 执行朗读
            Dispatch.call(sapo,"Speak",new Variant(readText));
            // 关闭执行对象
            sapo.safeRelease();
        }catch (Exception e){
            isFinish = false;
            e.printStackTrace();
        }finally {
            // 关闭执行对象
            sap.safeRelease();
        }
        return isFinish;
    }

}
